package com.atguigu.gulimall.product.app;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.product.entity.CategoryBrandRelationEntity;
import com.atguigu.gulimall.product.service.CategoryBrandRelationService;
import com.atguigu.gulimall.product.vo.BrandRelationList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 品牌分类关联表
 *
 * @author YuGuoJian
 * @email yu825074596@163.com
 * @date 2021-11-22 22:27:49
 */
@RestController
@RequestMapping("product/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 列表
     */
    @GetMapping("catelog/list")
    public R categoryList(@RequestParam("brandId") Long branId){
        List<CategoryBrandRelationEntity> data = categoryBrandRelationService.categoryList(branId);
        return R.ok().put("data", data);
    }
    ///product/categorybrandrelation/brands/list
    @GetMapping("brands/list")
    public R brandsList(@RequestParam(value = "catId") Long catId){
       List<BrandRelationList> list = categoryBrandRelationService.brandsList(catId);
       return R.ok().put("data",list);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        CategoryBrandRelationEntity CategoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("CategoryBrandRelation", CategoryBrandRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CategoryBrandRelationEntity CategoryBrandRelation){
        categoryBrandRelationService.saveDetail(CategoryBrandRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CategoryBrandRelationEntity CategoryBrandRelation){
        categoryBrandRelationService.updateById(CategoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
}
